import 'package:sonora/models/sj_country_data.dart';

class SjCountryUtils {
  static final SjCountryUtils _instance = SjCountryUtils._internal();
  List<SjCountryData>? _countrys;

  // 私有的构造函数
  SjCountryUtils._internal() {
    _init();
  }

  // 公共的静态方法来获取该实例
  static SjCountryUtils get instance => _instance;

  void _init() {
    if (_countrys == null) {
      final list =
          _countryString().map((e) => SjCountryData.fromJson(e)).toList();
      _countrys = List.from(list);
    }
  }

  List<Map<String, dynamic>> _countryString() {
    final List<Map<String, dynamic>> list = [
      {'name': 'Afghanistan'},
      {'name': 'Albania'},
      {'name': 'Algeria'},
      {'name': 'Andorra'},
      {'name': 'Angola'},
      {'name': 'Antigua and Barbuda'},
      {'name': 'Argentina'},
      {'name': 'Armenia'},
      {'name': 'Australia'},
      {'name': 'Austria'},
      {'name': 'Azerbaijan'},
      {'name': 'Bahamas'},
      {'name': 'Bahrain'},
      {'name': 'Bangladesh'},
      {'name': 'Barbados'},
      {'name': 'Belarus'},
      {'name': 'Belgium'},
      {'name': 'Belize'},
      {'name': 'Benin'},
      {'name': 'Bhutan'},
      {'name': 'Bolivia'},
      {'name': 'Bosnia and Herzegovina'},
      {'name': 'Botswana'},
      {'name': 'Brazil'},
      {'name': 'Brunei'},
      {'name': 'Bulgaria'},
      {'name': 'Burkina Faso'},
      {'name': 'Burundi'},
      {'name': 'Cabo Verde'},
      {'name': 'Cambodia'},
      {'name': 'Cameroon'},
      {'name': 'Canada'},
      {'name': 'Central African Republic'},
      {'name': 'Chad'},
      {'name': 'Chile'},
      {'name': 'Colombia'},
      {'name': 'Comoros'},
      {'name': 'Congo, Democratic Republic of the'},
      {'name': 'Congo, Republic of the'},
      {'name': 'Costa Rica'},
      {'name': 'Croatia'},
      {'name': 'Cuba'},
      {'name': 'Cyprus'},
      {'name': 'Czech Republic'},
      {'name': 'Denmark'},
      {'name': 'Djibouti'},
      {'name': 'Dominica'},
      {'name': 'Dominican Republic'},
      {'name': 'East Timor (Timor-Leste)'},
      {'name': 'Ecuador'},
      {'name': 'Egypt'},
      {'name': 'El Salvador'},
      {'name': 'Equatorial Guinea'},
      {'name': 'Eritrea'},
      {'name': 'Estonia'},
      {'name': 'Eswatini (Swaziland)'},
      {'name': 'Ethiopia'},
      {'name': 'Fiji'},
      {'name': 'Finland'},
      {'name': 'France'},
      {'name': 'Gabon'},
      {'name': 'Gambia'},
      {'name': 'Georgia'},
      {'name': 'Germany'},
      {'name': 'Ghana'},
      {'name': 'Greece'},
      {'name': 'Grenada'},
      {'name': 'Guatemala'},
      {'name': 'Guinea'},
      {'name': 'Guinea-Bissau'},
      {'name': 'Guyana'},
      {'name': 'Haiti'},
      {'name': 'Honduras'},
      {'name': 'Hungary'},
      {'name': 'Iceland'},
      {'name': 'India'},
      {'name': 'Indonesia'},
      {'name': 'Iran'},
      {'name': 'Iraq'},
      {'name': 'Ireland'},
      {'name': 'Israel'},
      {'name': 'Italy'},
      {'name': 'Ivory Coast'},
      {'name': 'Jamaica'},
      {'name': 'Japan'},
      {'name': 'Jordan'},
      {'name': 'Kazakhstan'},
      {'name': 'Kenya'},
      {'name': 'Kiribati'},
      {'name': 'Korea, North'},
      {'name': 'Korea, South'},
      {'name': 'Kosovo'},
      {'name': 'Kuwait'},
      {'name': 'Kyrgyzstan'},
      {'name': 'Laos'},
      {'name': 'Latvia'},
      {'name': 'Lebanon'},
      {'name': 'Lesotho'},
      {'name': 'Liberia'},
      {'name': 'Libya'},
      {'name': 'Liechtenstein'},
      {'name': 'Lithuania'},
      {'name': 'Luxembourg'},
      {'name': 'Madagascar'},
      {'name': 'Malawi'},
      {'name': 'Malaysia'},
      {'name': 'Maldives'},
      {'name': 'Mali'},
      {'name': 'Malta'},
      {'name': 'Marshall Islands'},
      {'name': 'Mauritania'},
      {'name': 'Mauritius'},
      {'name': 'Mexico'},
      {'name': 'Micronesia'},
      {'name': 'Moldova'},
      {'name': 'Monaco'},
      {'name': 'Mongolia'},
      {'name': 'Montenegro'},
      {'name': 'Morocco'},
      {'name': 'Mozambique'},
      {'name': 'Myanmar (Burma)'},
      {'name': 'Namibia'},
      {'name': 'Nauru'},
      {'name': 'Nepal'},
      {'name': 'Netherlands'},
      {'name': 'New Zealand'},
      {'name': 'Nicaragua'},
      {'name': 'Niger'},
      {'name': 'Nigeria'},
      {'name': 'North Macedonia'},
      {'name': 'Norway'},
      {'name': 'Oman'},
      {'name': 'Pakistan'},
      {'name': 'Palau'},
      {'name': 'Panama'},
      {'name': 'Papua New Guinea'},
      {'name': 'Paraguay'},
      {'name': 'Peru'},
      {'name': 'Philippines'},
      {'name': 'Poland'},
      {'name': 'Portugal'},
      {'name': 'Qatar'},
      {'name': 'Romania'},
      {'name': 'Russia'},
      {'name': 'Rwanda'},
      {'name': 'Saint Kitts and Nevis'},
      {'name': 'Saint Lucia'},
      {'name': 'Saint Vincent and the Grenadines'},
      {'name': 'Samoa'},
      {'name': 'San Marino'},
      {'name': 'Sao Tome and Principe'},
      {'name': 'Saudi Arabia'},
      {'name': 'Senegal'},
      {'name': 'Serbia'},
      {'name': 'Seychelles'},
      {'name': 'Sierra Leone'},
      {'name': 'Singapore'},
      {'name': 'Slovakia'},
      {'name': 'Slovenia'},
      {'name': 'Solomon Islands'},
      {'name': 'Somalia'},
      {'name': 'South Africa'},
      {'name': 'South Sudan'},
      {'name': 'Spain'},
      {'name': 'Sri Lanka'},
      {'name': 'Sudan'},
      {'name': 'Suriname'},
      {'name': 'Sweden'},
      {'name': 'Switzerland'},
      {'name': 'Syria'},
      {'name': 'Taiwan'},
      {'name': 'Tajikistan'},
      {'name': 'Tanzania'},
      {'name': 'Thailand'},
      {'name': 'Togo'},
      {'name': 'Tonga'},
      {'name': 'Trinidad and Tobago'},
      {'name': 'Tunisia'},
      {'name': 'Turkey'},
      {'name': 'Turkmenistan'},
      {'name': 'Tuvalu'},
      {'name': 'Uganda'},
      {'name': 'Ukraine'},
      {'name': 'United Arab Emirates'},
      {'name': 'United Kingdom'},
      {'name': 'United States'},
      {'name': 'Uruguay'},
      {'name': 'Uzbekistan'},
      {'name': 'Vanuatu'},
      {'name': 'Vatican City'},
      {'name': 'Venezuela'},
      {'name': 'Vietnam'},
      {'name': 'Yemen'},
      {'name': 'Zambia'},
      {'name': 'Zimbabwe'},
    ];
    return list;
  }

  List<Map<String, dynamic>> _countryJsonMap() {
    final list = [
      {"area": "\uD83C\uDF0D", "name": "Global", "free": true, "price": 0},
      {
        "area": "\uD83C\uDDFA\uD83C\uDDF8",
        "name": "America",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDEF\uD83C\uDDF5",
        "name": "Japan",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDE8\uD83C\uDDE6",
        "name": "Canada",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDE6\uD83C\uDDFA",
        "name": "Australia",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDEB\uD83C\uDDF7",
        "name": "France",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDF2\uD83C\uDDFE",
        "name": "Malaysia",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDF0\uD83C\uDDF7",
        "name": "South Korea",
        "free": false,
        "price": 12
      },
      {
        "area": "\uD83C\uDDFB\uD83C\uDDF3",
        "name": "Vietnam",
        "free": false,
        "price": 12
      }
    ];
    return list;
  }

  List<SjCountryData>? get countryList => _countrys;

  String? getCountryArea(String? countryName) {
    if (countryName == null || countryList == null) return null;
    List<SjCountryData> list =
        countryList!.where((element) => element.name == countryName).toList();
    if (list.isEmpty) return null;
    SjCountryData countryData = list.first;
    return countryData.name;
  }
}
